package com.gxjtkyy.datadistributer.writer.rdbms.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class ExceptionMessageService {
   private final String appName;
   private final JdbcTemplate jdbcTemplate;

   public ExceptionMessageService(@Value("${spring.application.name}") String appName, JdbcTemplate jdbcTemplate) {
      this.appName = appName;
      this.jdbcTemplate = jdbcTemplate;
   }

   public void saveExceptionMessage(String exceptionDescription, String record) {
      String sql = "insert into EXCEPTION_MESSAGE(ID, APP_NAME, EXCEPTION_DESCRIPTION,MESSAGE) values (exception_message_id_seq.nextval,?,?,?)";
      this.jdbcTemplate.update(sql, new Object[]{this.appName, exceptionDescription, record});
   }
}
